#include <iostream>
#include <memory>

using namespace std;

class Product
{
public:
    virtual void show() = 0;
    virtual ~Product() {};
};
class productA : public Product
{
public:
    productA()
    {
        cout << "ProductA()" << endl;
    }
    void show() override
    {
        cout << "ProductA() :: show()" << endl;
    }
};
class productB : public Product
{
public:
    productB()
    {
        cout << "ProductB()" << endl;
    }
    void show() override
    {
        cout << "ProductB() :: show()" << endl;
    }
};
class Factory
{
public:
    virtual Product *creatProduct() = 0;
    virtual ~Factory() {}
};
class FactoryA : public Factory
{
public:
    FactoryA()
    {
        cout << "FactoryA()" << endl;
    }
    Product *creatProduct() override
    {
        return new productA();
    }
    ~FactoryA()
    {
        cout << "~FactoryA()" << endl;
    }
};
class FactoryB : public Factory
{
public:
    FactoryB()
    {
        cout << "FactoryB()" << endl;
    }
    Product *creatProduct() override
    {
        return new productB();
    }
    ~FactoryB()
    {
        cout << "~FactoryB()" << endl;
    }
};

void test(){
    unique_ptr<Factory> factoryA(new FactoryA());
    unique_ptr<Product> productA(factoryA->creatProduct());
    productA->show();

    unique_ptr<Factory> factoryB(new FactoryB());
    unique_ptr<Product> productB(factoryB->creatProduct());
    productB->show();
}
int main(){
    test();
    return 0;
}